cmake_policy(SET CMP0048 NEW)
project(ac VERSION 0.1.0.0)

# lua version
include("../scripts/Findlua.cmake")

# include aux cmake scripts
include("../scripts/Gengetopt.cmake")
ADD_GENGETOPT_FILES(CMDLINE cmdline.ggo)

# lua install dir
set(LUA_INSTALL_ACDIR ${LUA_INSTALL_DIR}/ac)
# macro define
set(CONFIG_AC 1)

# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
	"${PROJECT_SOURCE_DIR}/config.h.in"
	"${PROJECT_BINARY_DIR}/config.h"
	)

include_directories("${CMAKE_CURRENT_BINARY_DIR}"
	"${PROJECT_BINARY_DIR}"
	"${PROJECT_SOURCE_DIR}/../include/")

# source file
set(ACLIST
aclua.c
aphash.c
main.c
message.c
net.c
process.c
approc.c
apsync.c
resip.c)

set(LIBLIST
../lib/chap.c
../lib/arg.c
../lib/log.c
../lib/common.c
../lib/dllayer.c
../lib/md5.c
../lib/mjson.c
../lib/msg.c
../lib/netlayer.c
../lib/acctllua.c
../lib/netdev.c
../lib/sockarr.c
../lib/system.c
../lib/thread.c)

# extra libs
find_package(Threads)
set (EXTRALIB ${LUA_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})

# target
add_executable(ac ${CMDLINE} ${ACLIST} ${LIBLIST} )
target_link_libraries (ac ${EXTRALIB})

# install
install(TARGETS ac DESTINATION bin)

# lua
file(GLOB LUA_PROG ./lua/*)
file(GLOB LUA_LIB ../lua/*)
install(FILES ${LUA_PROG} ${LUA_LIB} DESTINATION ${LUA_INSTALL_ACDIR})
